var header = "票房风云";
var currentFolderCode="iptvtest_001_011_003";
function $(_id){
	return document.getElementById(_id);
}

document.onkeypress = grabEvent;
document.onirkeypress = grabEvent;
document.onkeydown = grabEvent;
function grabEvent(event){
	var key_code = event.which;
		switch(key_code){
		case 1://上
		case 38:
			up();
			return 0;
			break;
			
		case 2://下
		case 40:
			down();
			return 0;
			break;
			
		case 3://左
		case 37:
			left();
			return 0;
			break;
			
		case 4://右
		case 39:
			right();
			return 0;
			break;
		
		case 13://确定
			sel();
			return 0;
			break;
	}
}
//获得分页参数

//获取栏目下资产列表

var menuHrefs = new Array(5);
///////////按钮————————区域链接///////////////////
///////////下页--按钮————————区域链接///////////////////
var currentPage = "1";
var pageCount = "2";
if(parseInt("1")<parseInt("2")){
	menuHrefs[0] = "?p=2&args=";
}else{
	menuHrefs[0] ="#menu10";
}
///////////上页--按钮————————区域链接///////////////////
if(parseInt("1")>1){
	menuHrefs[1]="?p=0&args=";
}else{
	menuHrefs[1] = "#menu1";
}


///////////返回--按钮————————区域链接///////////////////



menuHrefs[2] = "/a?u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011";





///////////首页--按钮————————区域链接///////////////////
menuHrefs[3] = "http://utc.hzdtv.tv:80/folder/iptvtest/RDIPTV_HZHX_IPS_02133041934619859/iptvtest_001.page";

///////////跳页--按钮————————区域链接///////////////////
menuHrefs[4] = "javascript:play(document.forms[0].textnum.value);";
///////////片库--按钮————————区域链接///////////////////
//华纳 我要订购
if(currentFolderCode=='iptvtest_001_011_005'){
	menuHrefs[5] ="http://125.210.207.86:8082/boss-self/newself/hzselfservice/hd/index.jsp?stbid=";
//院线速递 片花
}else if(currentFolderCode=='iptvtest_001_011_017'){
	
	
	menuHrefs[5] ="/a?u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011_017_001";
}else{
	//片库
	
	
	menuHrefs[5] ="/a?u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011_018";
}

var arrayNum = "10";
var listHrefs = [];
///////////0-10个图片————————区域链接///////////////////
var num = 0;

	
	
	<!--.取到海报图片.-->
	
	
			
				
					
				
			
				
			
				
			
				
			
				
			
			<!--.取海报图片结束.-->
			<!--.设置图片路径.-->
			
				
			
			
	listHrefs[num] = {img:"http://125.210.227.11:8080/data/pic//data/pic/201202/20120219154138_chaoshikongjiubing138181xiaotu_3586108171329740153299.jpg", text:getSubStr("超时空救兵",6), url:"movie_detail.htm",flag:"false"};
	num++;

	
	
	<!--.取到海报图片.-->
	
	
			
				
			
				
			
				
					
				
			
				
			
				
			
			<!--.取海报图片结束.-->
			<!--.设置图片路径.-->
			
				
			
			
	listHrefs[num] = {img:"http://125.210.227.11:8080/data/pic//data/pic/201202/20120202102412_kaixindamaoxian138181xiaotu_3541033711328248615846.jpg", text:getSubStr("开心大冒险",6), url:"http://utc.hzdtv.tv:80/a?t=36&u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011_003&a=4166057",flag:"false"};
	num++;

	
	
	<!--.取到海报图片.-->
	
	
			
				
					
				
			
				
			
				
			
				
			
				
			
			<!--.取海报图片结束.-->
			<!--.设置图片路径.-->
			
				
			
			
	listHrefs[num] = {img:"http://125.210.227.11:8080/data/pic//data/pic/201201/20120116095357_shuangrenchuangtiaoyuedahaibao_3513472431326965677607.jpg", text:getSubStr("双人床条约",6), url:"http://utc.hzdtv.tv:80/a?t=36&u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011_003&a=3950723",flag:"false"};
	num++;

	
	
	<!--.取到海报图片.-->
	
	
			
				
			
				
			
				
			
				
					
				
			
				
					
				
			
				
			
				
			
				
			
			<!--.取海报图片结束.-->
			<!--.设置图片路径.-->
			
				
			
			
	listHrefs[num] = {img:"http://125.210.227.11:8080/data/pic///20111022/movie/138_181/59w.jpg", text:getSubStr("国王的演讲",6), url:"http://utc.hzdtv.tv:80/a?t=36&u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011_003&a=2022627",flag:"false"};
	num++;

	
	
	<!--.取到海报图片.-->
	
	
			
				
			
				
			
				
					
				
			
				
			
				
			
			<!--.取海报图片结束.-->
			<!--.设置图片路径.-->
			
				
			
			
	listHrefs[num] = {img:"http://125.210.227.11:8080/data/pic//data/pic/201202/20120203093917_hunlipaidui138181xiaotu_3544269121328579217073.jpg", text:getSubStr("婚礼派对",6), url:"http://utc.hzdtv.tv:80/a?t=36&u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011_003&a=4200802",flag:"false"};
	num++;

	
	
	<!--.取到海报图片.-->
	
	
			
				
					
				
			
				
			
				
			
				
			
				
			
			<!--.取海报图片结束.-->
			<!--.设置图片路径.-->
			
				
			
			
	listHrefs[num] = {img:"http://125.210.227.11:8080/data/pic//data/pic/201201/20120129150149_aboluoshisanhaodahaibao_3533641091327914705118.jpg", text:getSubStr("阿波罗13号",6), url:"http://utc.hzdtv.tv:80/a?t=36&u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011_003&a=4105147",flag:"false"};
	num++;

	
	
	<!--.取到海报图片.-->
	
	
			
				
					
				
			
				
			
				
			
				
			
				
			
			<!--.取海报图片结束.-->
			<!--.设置图片路径.-->
			
				
			
			
	listHrefs[num] = {img:"http://125.210.227.11:8080/data/pic//data/pic/201202/20120203144057_heijindiguodahaibao_3544889101328528256888.jpg", text:getSubStr("黑金帝国",6), url:"http://utc.hzdtv.tv:80/a?t=36&u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011_003&a=4206466",flag:"false"};
	num++;

	
	
	<!--.取到海报图片.-->
	
	
			
				
					
				
			
				
			
				
			
				
			
				
			
			<!--.取海报图片结束.-->
			<!--.设置图片路径.-->
			
				
			
			
	listHrefs[num] = {img:"http://125.210.227.11:8080/data/pic//data/pic/201202/20120202161213_taitannikehaodahaibao_3542261531328248455696.jpg", text:getSubStr("泰坦尼克号",6), url:"http://utc.hzdtv.tv:80/a?t=36&u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011_003&a=4165949",flag:"false"};
	num++;

	
	
	<!--.取到海报图片.-->
	
	
			
				
					
				
			
				
			
				
			
				
			
				
			
			<!--.取海报图片结束.-->
			<!--.设置图片路径.-->
			
				
			
			
	listHrefs[num] = {img:"http://125.210.227.11:8080/data/pic//data/pic/201201/20120118164527_lvjurendahaibao_3518119791326964537855.jpg", text:getSubStr("绿巨人",6), url:"http://utc.hzdtv.tv:80/a?t=36&u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011_003&a=3947074",flag:"false"};
	num++;

	
	
	<!--.取到海报图片.-->
	
	
			
				
					
				
			
				
			
				
			
				
			
				
			
			<!--.取海报图片结束.-->
			<!--.设置图片路径.-->
			
				
			
			
	listHrefs[num] = {img:"http://125.210.227.11:8080/data/pic//data/pic/201201/20120130130400_diezhongdie2dahaibao_3535525821327979253843.jpg", text:getSubStr("碟中谍2",6), url:"http://utc.hzdtv.tv:80/a?t=36&u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011_003&a=4115390",flag:"false"};
	num++;



var btnHrefs = new Array(2);
///////////返回--按钮————————区域链接///////////////////
btnHrefs[0] = "/a?u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011";




///////////首页--按钮————————区域链接///////////////////
btnHrefs[1] = "http://utc.hzdtv.tv:80/folder/iptvtest/RDIPTV_HZHX_IPS_02133041934619859/iptvtest_001.page";

/**
 * 0: menu; 1:list, 2:btn
 */
var area = 0;

//menu
var _menu_index = 0;
var max_menu_index = 5;
var textnum_menu_index = 4;

//list
var _list_index = 0;
var list_pic_count = 5;
var max_list_index = listHrefs.length - 1;
var _list = 0;
var max_list = 1;
var init_list_top = 178;
var max_list_top = 419;
var max_list_left = 793;
var init_list_left = 53;
var _list_top = init_list_top;
var inc_list_top = 232;
var _list_left = init_list_left;
var inc_list_left = 185;

//btn
var _btn_index = 0;
var max_btn_index = 1;

//sync
var is_sync = false;

function up(){
	if(is_sync) return;
	is_sync = true;
	switch(area){
		case 0:
			break;
		case 1:
			if(_list == 0){
				area = 0;
				$("float_choose").style.opacity = 0;
				listOut();
				menuIn();
			}else{
				_list_top -= inc_list_top;
				_list_index -= list_pic_count;
				incTopList(-1);
			}
			break;
		case 2:
			area = 1;
			$("float_choose").style.opacity = 1;
			btnOut();
			listIn();
			break;
	}
	is_sync = false;
}
function down(){
	if(is_sync) return;
	is_sync = true;
	switch(area){
		case 0:
			area = 1;
			$("float_choose").style.opacity = 1;
			menuOut();
			listIn();
			break;
		case 1:
			if(_list == max_list || (_list_index + list_pic_count)>max_list_index){
				area = 2;
				$("float_choose").style.opacity = 0;
				listOut();
				btnIn();
			}else{
				_list_top += inc_list_top;
				_list_index += list_pic_count;
				incTopList(1);
			}
			break;
		case 2:
			break;
	}
	is_sync = false;
}

function left(){
	if(is_sync) return;
	is_sync = true;
	switch(area){
		case 0:
			incMenu(-1)
			break;
		case 1:
			if((_list_index>0 && _list_index<list_pic_count) || (_list_index>list_pic_count && _list_index<=max_list_index)){
				_list_left -= inc_list_left;
				incLeftList(-1);
			} else if(_list_index == list_pic_count && _list == max_list){
				_list_top -= inc_list_top;
				_list_left = max_list_left;
				$("float_choose").style.left = _list_left+ "px";
				_list_index -= 1;
				incTopList(-1);
			} else {
				area = 0;
				$("float_choose").style.opacity = 0;
				listOut();
				menuIn();
			}
			break;
		case 2:
			if(!incBtn(-1)){
				area = 1;
				$("float_choose").style.opacity = 1;
				btnOut();
				listIn();
			}
			break;
	}
	is_sync = false;
}
function right(){
	if(is_sync) return;
	is_sync = true;
	switch(area){
		case 0:
			if(!incMenu(1)){
				area = 1;
				_list_top = init_list_top;
				_list_left = init_list_left;
				_list_index = 0;
				$("float_choose").style.left = _list_left+ "px";
				$("float_choose").style.top = _list_top+ "px";
				$("float_choose").style.opacity = 1;
				menuOut();
				listIn();
			}
			break;
		case 1:
			var _right_max_index = (list_pic_count-1)>max_list_index ? max_list_index : (list_pic_count-1);
			if((_list_index>=0 && _list_index<_right_max_index) || (_list_index >_right_max_index && _list_index < max_list_index)){
				_list_left += inc_list_left;
				incLeftList(1);
			} else /*if(_list == max_list) */{
				area = 2;
				$("float_choose").style.opacity = 0;
				listOut();
				btnIn();
			}
			break;
		case 2:
			incBtn(1);
			break;
	}
	is_sync = false;
}

//menu functions
function menuIn(){
	if(_menu_index == textnum_menu_index){
		$("textnum").focus();
	} else {
		$("textnum").blur();
		var __index = _menu_index;
		if(_menu_index == max_menu_index){
			__index = _menu_index - 1;
		}
		if(currentFolderCode=='iptvtest_001_011_005'){
			if(__index==4){
				$("menu_"+__index).src = "http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/images/mov/wydg_hot.png";
			}else{
				$("menu_"+__index).src = "http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/images/mov/menu_bk_hover"+__index+".png";
			}
		}else if(currentFolderCode=='iptvtest_001_011_017'){
			if(__index==4){
				$("menu_"+__index).src = "http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/images/mov/ph_hot.png";
			}else{
				$("menu_"+__index).src = "http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/images/mov/menu_bk_hover"+__index+".png";
			}
		}else{
			$("menu_"+__index).src = "http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/images/mov/menu_bk_hover"+__index+".png";
		}
	}
}
function menuOut(){
	if(_menu_index != textnum_menu_index){
		var __index = _menu_index;
		if(_menu_index == max_menu_index){
			__index = _menu_index - 1;
		}
		if(currentFolderCode=='iptvtest_001_011_005'){
			if(__index==4){
				$("menu_"+__index).src = "http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/images/mov/wydg.png";
			}else{
				$("menu_"+__index).src = "http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/images/mov/menu_bk"+__index+".png";
			}
		}else if(currentFolderCode=='iptvtest_001_011_017'){
			if(__index==4){
				$("menu_"+__index).src = "http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/images/mov/ph.png";
			}else{
				$("menu_"+__index).src = "http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/images/mov/menu_bk"+__index+".png";
			}
		}else{
			$("menu_"+__index).src = "http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/images/mov/menu_bk"+__index+".png";
		}	
	}
	$("textnum").blur();
}

function incMenu(inc){
	var new_menu_index = _menu_index + inc;
	if(new_menu_index<0 || new_menu_index>max_menu_index) return false;

	menuOut();
	_menu_index = new_menu_index;
	menuIn();
	return true;
}

//btn functions
function btnIn(){
	$("btn_"+_btn_index).src = "http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/images/mov/btn_bk_hover"+_btn_index+".png";
}
function btnOut(){
	$("btn_"+_btn_index).src = "http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/images/mov/btn_bk"+_btn_index+".png";
}

function incBtn(inc){
	var new_btn_index = _btn_index + inc;
	if(new_btn_index<0 || new_btn_index>max_btn_index) return false;

	btnOut();
	_btn_index = new_btn_index;
	btnIn();
	return true;
}

//list functions
function initLists(){
	for(var i=0; i<10; i++){
		if(i >= listHrefs.length){
			$("pic"+i).style.visibility = "hidden";
			$("list"+i).style.visibility = "hidden";
		} else {
			$("pic"+i).src = listHrefs[i].img;
			if(listHrefs[i].flag=='true'){
				$("list"+i).innerText = listHrefs[i].text;
			}
		}
	}
}
function listIn(){
	//Skip
}
function listOut(){
	//Skip
}
function incTopList(inc){
	$("float_choose").style.top = _list_top + "px";
	listOut();
	_list += inc;
	listIn();
}
function incLeftList(inc){
	$("float_choose").style.left = _list_left + "px";
	listOut();
	_list_index  += inc;
	listIn();
}

function sel(){

	switch(area){
		case 0:
			window.location.href = menuHrefs[_menu_index];
			break;
		case 1:
			window.location.href = listHrefs[_list_index].url;
			break;
		case 2:
			window.location.href = btnHrefs[_btn_index];
			break;
	}
}
function play(_page){
	//alert(_page);
	var pageNum = parseInt(_page);
	if(pageNum>0&&pageNum<=parseInt("2")){
	window.location.href = "?p="+pageNum;
	}else{
		return;
	}
}

function init(){
	$("header").innerHTML = header;
	initLists();
	document.getElementById("pageCount").innerHTML = "1"+"/"+"2";
}

function getSubStr(str,num){
    var num = num;
	if(str.length > num){
		str = str.substr(0,num)+"..";
	}
	return str;
}